﻿#ifndef __DAHUA_GENICAM_IEVENTSUBSCRIBE_H__
#define __DAHUA_GENICAM_IEVENTSUBSCRIBE_H__

#include "Defs.h"
#include "Memory/SharedPtr.h"
#include "Infra/Function.h"
#include "Infra/Vector.h"
#include "Infra/String.h"

GENICAM_NAMESPACE_BEGIN

/// \~chinese
/// \brief Struct 杩炴帴浜嬩欢鍙傛暟灏佽
/// \~english
/// \brief Struct connection event parameters encapsulation
struct SConnectArg
{
	enum EVType
	{
		offLine,   ///< \~chinese 璁惧绂荤嚎阃氱煡    ///< \~english device offline notification
		onLine     ///< \~chinese 璁惧鍦ㄧ嚎阃氱煡 	  ///< \~english device online notification
	};
	EVType m_event;  		///< \~chinese 浜嬩欢绫诲瀷    ///< \~english event type
	uint32_t reserve[15];   ///< \~chinese 棰勭暀瀛楁    ///< \~english reserved field
};

/// \~chinese
/// \brief Struct 鍙傛暟镟存柊浜嬩欢鍙傛暟灏佽
/// \~english
/// \brief Struct updating parameters event encapsulation
struct SParamUpdataArg
{
	bool isPoll; 					   ///< \~chinese 鏄惁鏄畾镞舵洿鏂?1琛ㄧず鏄畾镞舵洿鏂帮紝0琛ㄧず闱炲畾镞舵洿鏂?  ///< \~english update periodically or not. 1 : update periodically, 0 : not update periodically
	uint32_t reserve[10];		       ///< \~chinese 棰勭暀瀛楁                 ///< \~english reserved field
	Infra::TVector<Infra::CString>  paramNames; ///< \~chinese 镟存柊镄勫弬鏁板悕绉伴泦鍚?绾﹀畾镟存柊镄勫弬鏁颁笉瓒呰绷1000涓紝姣忎釜鍙傛暟镄勫瓧绗︿覆闀垮害涓嶈秴杩?56  ///< \~english array of parameter's name which need to be updated. the maximum number of parameters is 1000. and the max length of strings of each parameter is 255.
};

/// \~chinese
///鏋氢妇锛氭祦浜嬩欢钟舵€?
/// \~english
/// enumeration:stream event status
enum EEventStatus
{
	streamEventNormal = 1,    ///< \~chinese 姝ｅ父娴佷簨浠?	    ///< \~english normal stream event
	streamEventLostFrame = 2, ///< \~chinese 涓㈠抚浜嬩欢		    ///< \~english lost frame event
	streamEventLostPacket = 3,///< \~chinese 涓㈠寘浜嬩欢		    ///< \~english lost packet event
	streamEventImageError = 4,    ///< \~chinese 锲惧儚阌栾浜嬩欢		///< \~english error image event
	streamEventStreamChannelError     ///< \~chinese 鍙栨祦阌栾浜嬩欢 		///< \~english stream channel error event
};

/// \~chinese
/// \brief Struct 娴佷簨浠跺弬鏁板皝瑁?
/// \~english
/// \brief Struct stream event parameters encapsulation
struct SStreamArg
{
	uint32_t     channel;            ///< \~chinese 娴侀€氶亾鍙?        ///< \~english stream channel no.
	uint64_t     blockID;            ///< \~chinese 娴佹暟鎹瓸lockID    ///< \~english block ID of stream data
	uint64_t     timestamp;          ///< \~chinese 镞堕棿鎴?          ///< \~english event timestamp
	EEventStatus eStreamEventStatus; ///< \~chinese 娴佷簨浠剁姸镐佺爜     ///< \~english stream event status code
	uint32_t	 status;			 ///< \~chinese 浜嬩欢钟舵€侀敊璇爜   ///< \~english status error code
	uint32_t reserve[9];			 ///< \~chinese 棰勭暀瀛楁         ///< \~english reserved field
};

/// \~chinese
/// 娑堟伅阃氶亾浜嬩欢ID鍒楄〃
/// \~english
/// message channel event id list
#define MSG_EVENT_ID_EXPOSURE_END			0x9001
#define MSG_EVENT_ID_FRAME_TRIGGER			0x9002
#define MSG_EVENT_ID_FRAME_START			0x9003
#define MSG_EVENT_ID_ACQ_START				0x9004
#define MSG_EVENT_ID_ACQ_TRIGGER			0x9005
#define MSG_EVENT_ID_DATA_READ_OUT			0x9006

/// \~chinese
/// \brief Struct 娑堟伅阃氶亾浜嬩欢鍙傛暟灏佽
/// \~english
/// \brief Struct message channel event parameters encapsulation
struct SMsgChannelArg
{
	uint16_t  eventID;         ///< \~chinese 浜嬩欢Id			///< \~english event id
	uint16_t  channelID;       ///< \~chinese 娑堟伅阃氶亾鍙?	///< \~english channel id
	uint64_t  blockID;		   ///< \~chinese 娴佹暟鎹瓸lockID		///< \~english block ID of stream data
	uint64_t  timeStamp;       ///< \~chinese 镞堕棿鎴?		///< \~english event timestamp
	uint32_t    reserve[8];   ///< \~chinese 棰勭暀瀛楁         ///< \~english reserved field
	Infra::TVector<Infra::CString>  paramNames;   ///< \~chinese 浜嬩欢鐩稿叧镄勫睘镐у悕鍒楄〃銆傜害瀹氩睘镐у悕涓嶈秴杩?000涓紝姣忎釜灞炴€у悕镄勫瓧绗︿覆闀垮害涓嶈秴杩?56  ///< \~english array of parameter's name which is related. the maximum number of parameters is 1000. and the max length of strings of each parameter is 255.
};

/// \~chinese
/// \brief 璁惧杩炴帴钟舵€佷簨浠跺洖璋冨嚱鏁板０鏄?
/// \~english
/// \brief call back function declaration of camera connection status event 
typedef Infra::TFunction1<void, const SConnectArg&> ConnectArgProc;

/// \~chinese
/// \brief 璁惧杩炴帴钟舵€佷簨浠跺洖璋冨嚱鏁板０鏄?
/// \~english
/// \brief call back function declaration of camera connection status event 
typedef Infra::TFunction2<void, const SConnectArg&, void*> ConnectArgProcEx;

/// \~chinese
/// \brief 鍙傛暟镟存柊浜嬩欢锲炶皟鍑芥暟澹版槑
/// \~english
/// \brief call back function declaration of camera parameter update event 
typedef Infra::TFunction1<void, const SParamUpdataArg&> ParamUpdataProc;

/// \~chinese
/// \brief 鍙傛暟镟存柊浜嬩欢锲炶皟鍑芥暟澹版槑
/// \~english
/// \brief call back function declaration of camera parameter update event 
typedef Infra::TFunction2<void, const SParamUpdataArg&, void*> ParamUpdataProcEx;

/// \~chinese
/// \brief 璁惧娴佷簨浠跺洖璋冨嚱鏁板０鏄?
/// \~english
/// \brief call back function declaration of stream event 
typedef Infra::TFunction1<void, const SStreamArg&> StreamArgProc;

/// \~chinese
/// \brief 璁惧娴佷簨浠跺洖璋冨嚱鏁板０鏄?
/// \~english
/// \brief call back function declaration of stream event 
typedef Infra::TFunction2<void, const SStreamArg&, void*> StreamArgProcEx;

/// \brief 娑堟伅阃氶亾浜嬩欢锲炶皟鍑芥暟澹版槑
/// \~english
/// \brief call back function declaration of message channel event 
typedef Infra::TFunction1<void, const SMsgChannelArg&> MsgChannelProc;

/// \brief 娑堟伅阃氶亾浜嬩欢锲炶皟鍑芥暟澹版槑
/// \~english
/// \brief call back function declaration of message channel event 
typedef Infra::TFunction2<void, const SMsgChannelArg&, void*> MsgChannelProcEx;

/// \~chinese
/// \brief 浜嬩欢娉ㄥ唽锲炶皟瀵硅薄鎺ュ彛绫?
/// \defgroup Event 鐩告満浜嬩欢璁㈤槄娉ㄥ唽涓庡幓娉ㄥ唽鎺ュ彛
/// @{
/// \~english
/// \brief event register callback function interface class
/// \defgroup Event Event Notification subscribe and unsubscribe interface
/// @{

/// \~chinese
/// \brief Class IEventSubscribe 浜嬩欢娉ㄥ唽锲炶皟瀵硅薄鎺ュ彛绫伙紝鍏朵腑鍖呮嫭璁惧钟舵€佷簨浠躲€佹祦阃氶亾浜嬩欢鍙婂弬鏁版洿鏂颁簨浠?
/// \~english
/// \brief Class IEventSubscribe Event subscribe callback object interface class锛宨ncluding device status events銆乻tream channel events and parameter update events

class GENICAM_API IEventSubscribe
{
public:
	/// \~chinese
	/// \brief 鏋愭瀯鍑芥暟
	/// \~english
	/// \brief destructor	
	virtual ~IEventSubscribe(){}

public:
	/// \~chinese
	/// \brief  璁惧杩炴帴钟舵€佷簨浠跺洖璋冩敞鍐?
	/// \param [in] proc  璁惧杩炴帴钟舵€佷簨浠跺洖璋冩敞鍐屽嚱鏁?
	/// \return 娉ㄥ唽鏄惁鎴愬姛
	/// \~english
	/// \brief  regist call back function of camera connection status event. only one call back function is supported.
	/// \param [in] proc  call back function of camera connection status event
	/// \return the result of registration ( Success or fail )
	virtual bool subscribeConnectArgs(ConnectArgProc const& proc) = 0;

	/// \~chinese
	/// \brief  璁惧杩炴帴钟舵€佷簨浠跺洖璋冨幓娉ㄥ唽
	/// \param [in] proc  璁惧杩炴帴钟舵€佷簨浠跺洖璋冨幓娉ㄥ唽鍑芥暟
	/// \return 铡绘敞鍐屾槸鍚︽垚锷?
	/// \~english
	/// \brief  unregister call back function of camera connection status event.
	/// \param [in] proc  Unregister call back function of camera connection status event
	/// \return the result of unregistration ( Success or fail )	
	virtual bool unsubscribeConnectArgs(ConnectArgProc const& proc) = 0;

	/// \~chinese
	/// \brief  鍙傛暟镟存柊浜嬩欢锲炶皟娉ㄥ唽
	/// \param [in] proc 鍙傛暟镟存柊娉ㄥ唽镄勪簨浠跺洖璋冨嚱鏁?
	/// \return 娉ㄥ唽鏄惁鎴愬姛
	/// \~english
	/// \brief  regist call back function of parameter update event. only one call back function is supported.
	/// \param [in] proc  call back function of parameter update event
	/// \return the result of registration	( Success or fail )
	virtual bool subscribeParamUpdate(ParamUpdataProc const& proc) = 0;

	/// \~chinese
	/// \brief  鍙傛暟镟存柊浜嬩欢锲炶皟铡绘敞鍐?
	/// \param [in] proc 鍙傛暟镟存柊浜嬩欢铡绘敞鍐岀殑锲炶皟鍑芥暟
	/// \return 铡绘敞鍐屾槸鍚︽垚锷?
	/// \~english
	/// \brief  unregister call back function of parameter update event.
	/// \param [in] proc  unregister call back function of parameter update event
	/// \return the result of unregistration ( Success or fail )	
	virtual bool unsubscribeParamUpdate(ParamUpdataProc const& proc) = 0;

	/// \~chinese
	/// \brief  娴侀€氶亾浜嬩欢锲炶皟娉ㄥ唽
	/// \param [in] proc 娴侀€氶亾浜嬩欢锲炶皟娉ㄥ唽鍑芥暟
	/// \return 娉ㄥ唽鏄惁鎴愬姛
	/// \~english
	/// \brief  register call back function of stream channel event. only one call back function is supported.
	/// \param [in] proc  register call back function of stream channel event
	/// \return the result of registration ( Success or fail )	
	virtual bool subscribeStreamArg(StreamArgProc const& proc) = 0;

	/// \~chinese
	/// \brief  娴侀€氶亾浜嬩欢锲炶皟铡绘敞鍐?
	/// \param [in] proc  娴侀€氶亾浜嬩欢锲炶皟铡绘敞鍐屽嚱鏁?
	/// \return 铡绘敞鍐屾槸鍚︽垚锷?
	/// \~english
	/// \brief  unregister call back function of stream channel event.
	/// \param [in] proc  unregister call back function of tream channel event
	/// \return the result of unregistration ( Success or fail )	
	virtual bool unsubscribeStreamArg(StreamArgProc const& proc) = 0;

    /// \~chinese
    /// \brief  璁惧杩炴帴钟舵€佷簨浠跺洖璋冩敞鍐?
    /// \param [in] proc  璁惧杩炴帴钟舵€佷簨浠跺洖璋冩敞鍐屽嚱鏁?
    /// \param [in] pUser  鐢ㄦ埛镊畾涔夋暟鎹?
    /// \return 娉ㄥ唽鏄惁鎴愬姛
    /// \~english
    /// \brief  regist call back function of camera connection status event. only one call back function is supported.
    /// \param [in] proc  call back function of camera connection status event
    /// \param [in] pUser  user data
    /// \return the result of registration ( Success or fail )
    virtual bool subscribeConnectArgsEx(ConnectArgProcEx const& proc, void* pUser) = 0;

    /// \~chinese
    /// \brief  璁惧杩炴帴钟舵€佷簨浠跺洖璋冨幓娉ㄥ唽
    /// \param [in] proc  璁惧杩炴帴钟舵€佷簨浠跺洖璋冨幓娉ㄥ唽鍑芥暟
    /// \param [in] pUser  鐢ㄦ埛镊畾涔夋暟鎹?
    /// \return 铡绘敞鍐屾槸鍚︽垚锷?
    /// \~english
    /// \brief  unregister call back function of camera connection status event.
    /// \param [in] proc  Unregister call back function of camera connection status event
    /// \param [in] pUser  user data
    /// \return the result of unregistration ( Success or fail )	
    virtual bool unsubscribeConnectArgsEx(ConnectArgProcEx const& proc, void* pUser) = 0;

    /// \~chinese
    /// \brief  鍙傛暟镟存柊浜嬩欢锲炶皟娉ㄥ唽
    /// \param [in] proc 鍙傛暟镟存柊娉ㄥ唽镄勪簨浠跺洖璋冨嚱鏁?
    /// \param [in] pUser  鐢ㄦ埛镊畾涔夋暟鎹?
    /// \return 娉ㄥ唽鏄惁鎴愬姛
    /// \~english
    /// \brief  regist call back function of parameter update event. only one call back function is supported.
    /// \param [in] proc  call back function of parameter update event
    /// \param [in] pUser  user data
    /// \return the result of registration	( Success or fail )
    virtual bool subscribeParamUpdateEx(ParamUpdataProcEx const& proc, void* pUser) = 0;

    /// \~chinese
    /// \brief  鍙傛暟镟存柊浜嬩欢锲炶皟铡绘敞鍐?
    /// \param [in] proc 鍙傛暟镟存柊浜嬩欢铡绘敞鍐岀殑锲炶皟鍑芥暟
    /// \param [in] pUser  鐢ㄦ埛镊畾涔夋暟鎹?
    /// \return 铡绘敞鍐屾槸鍚︽垚锷?
    /// \~english
    /// \brief  unregister call back function of parameter update event.
    /// \param [in] proc  unregister call back function of parameter update event
    /// \param [in] pUser  user data
    /// \return the result of unregistration ( Success or fail )
    virtual bool unsubscribeParamUpdateEx(ParamUpdataProcEx const& proc, void* pUser) = 0;

    /// \~chinese
    /// \brief  娴侀€氶亾浜嬩欢锲炶皟娉ㄥ唽
    /// \param [in] proc 娴侀€氶亾浜嬩欢锲炶皟娉ㄥ唽鍑芥暟
    /// \param [in] pUser  鐢ㄦ埛镊畾涔夋暟鎹?
    /// \return 娉ㄥ唽鏄惁鎴愬姛
    /// \~english
    /// \brief  register call back function of stream channel event. only one call back function is supported.
    /// \param [in] proc  register call back function of stream channel event
    /// \param [in] pUser  user data
    /// \return the result of registration ( Success or fail )	
    virtual bool subscribeStreamArgEx(StreamArgProcEx const& proc, void* pUser) = 0;

    /// \~chinese
    /// \brief  娴侀€氶亾浜嬩欢锲炶皟铡绘敞鍐?
    /// \param [in] proc  娴侀€氶亾浜嬩欢锲炶皟铡绘敞鍐屽嚱鏁?
    /// \param [in] pUser  鐢ㄦ埛镊畾涔夋暟鎹?
    /// \return 铡绘敞鍐屾槸鍚︽垚锷?
    /// \~english
    /// \brief  unregister call back function of stream channel event.
    /// \param [in] proc  unregister call back function of tream channel event
    /// \param [in] pUser  user data
    /// \return the result of unregistration ( Success or fail )
    virtual bool unsubscribeStreamArgEx(StreamArgProcEx const& proc, void* pUser) = 0;

	/// \~chinese
	/// \brief  娑堟伅阃氶亾浜嬩欢锲炶皟娉ㄥ唽
	/// \param [in] proc 娑堟伅阃氶亾浜嬩欢锲炶皟娉ㄥ唽鍑芥暟
	/// \return 娉ㄥ唽鏄惁鎴愬姛
	/// \~english
	/// \brief  register call back function of message channel event. only one call back function is supported.
	/// \param [in] proc  register call back function of message channel event
	/// \return the result of registration ( Success or fail )	
	virtual bool subscribeMsgChannel(MsgChannelProc const& proc) = 0;

	/// \~chinese
	/// \brief  娑堟伅阃氶亾浜嬩欢锲炶皟铡绘敞鍐?
	/// \param [in] proc  娑堟伅阃氶亾浜嬩欢锲炶皟铡绘敞鍐屽嚱鏁?
	/// \return 铡绘敞鍐屾槸鍚︽垚锷?
	/// \~english
	/// \brief  unregister call back function of message channel event.
	/// \param [in] proc  unregister call back function of message channel event
	/// \return the result of unregistration ( Success or fail )	
	virtual bool unsubscribeMsgChannel(MsgChannelProc const& proc) = 0;

	/// \~chinese
	/// \brief  娑堟伅阃氶亾浜嬩欢锲炶皟娉ㄥ唽
	/// \param [in] proc 娑堟伅阃氶亾浜嬩欢锲炶皟娉ㄥ唽鍑芥暟
	/// \param [in] pUser  鐢ㄦ埛镊畾涔夋暟鎹?
	/// \return 娉ㄥ唽鏄惁鎴愬姛
	/// \~english
	/// \brief  register call back function of message channel event. only one call back function is supported.
	/// \param [in] proc  register call back function of message channel event
	/// \param [in] pUser  user data
	/// \return the result of registration ( Success or fail )	
	virtual bool subscribeMsgChannelEx(MsgChannelProcEx const& proc, void* pUser) = 0;

	/// \~chinese
	/// \brief  娑堟伅阃氶亾浜嬩欢锲炶皟铡绘敞鍐?
	/// \param [in] proc  娑堟伅阃氶亾浜嬩欢锲炶皟铡绘敞鍐屽嚱鏁?
	/// \param [in] pUser  鐢ㄦ埛镊畾涔夋暟鎹?
	/// \return 铡绘敞鍐屾槸鍚︽垚锷?
	/// \~english
	/// \brief  unregister call back function of message channel event.
	/// \param [in] proc  unregister call back function of message channel event
	/// \param [in] pUser  user data
	/// \return the result of unregistration ( Success or fail )	
	virtual bool unsubscribeMsgChannelEx(MsgChannelProcEx const& proc, void* pUser) = 0;
};

typedef Memory::TSharedPtr<IEventSubscribe> IEventSubscribePtr;
/// @}

GENICAM_NAMESPACE_END
#endif //__DAHUA_GENICAM_IEVENTSUBSCRIBE_H__